<?php 
	require("config.php");
	$tableCmd = array (
		"create table ".$DBP."passdb(uid CHAR(32), PRIMARY KEY(uid), passwd CHAR(64))",
		"create table ".$DBP."cumap(cid CHAR(8), PRIMARY KEY(uid), uid CHAR(32))",
		"create table ".$DBP."user(uid CHAR(32), PRIMARY KEY(uid), cid CHAR(8), cname CHAR(32), rpass CHAR(6),".
			 "email CHAR(64))",
		"create table ".$DBP."counter(name CHAR(16), PRIMARY KEY(name), count INT)"
	);
	$conn = connectDB() or die("Connect error");

	$sql = "drop database $DB_NAME";
	mysql_query($sql, $conn) or die("drop fail\n");

	$sql = "create database $DB_NAME";
	mysql_query($sql, $conn) or die ("create fail \n");

	$sql = "use $DB_NAME";
	mysql_query($sql, $conn) or die ("use fail\n");

	for($i=0;$i<count($tableCmd);$i++) {
		if(! mysql_query($tableCmd[$i], $conn)) {
			$cmd = $tableCmd[$i];
			echo "Command $cmd Fails \n";
		}
	}
	$sql = "insert into $DBP"."counter (name, count) values ('company', 13200)";
	mysql_query($sql, $conn) || die("init company count fails\n");

?>
